#ifndef _MARCHING_CUBE_RENDER_H
#define _MARCHING_CUBE_RENDER_H

#include "mtxlib.h"
#include <stdlib.h>
#include <iostream>
#include <bitset>
#include "PointFactory.h"
#include "TriangleFactory.h"
#include "MarchingCubeTable.h"

#ifndef CUBE_SIZE
#define CUBE_SIZE (0.125)
#endif

#ifndef HALF_CUBE_SIZE
#define HALF_CUBE_SIZE (CUBE_SIZE / 2)
#endif

class MarchingCubeRender{
	protected:
		static MarchingCubeRender* mcr;

		static vector3 pos[8];

		MarchingCubeRender(){

		}

	public:
		static MarchingCubeRender* getInstance();

		void calculate();

	public:
		void calculateCube(float density[8], vector3 originPos);

		Point* calculateIntersection(float density[8], int a, int b, vector3 originPos, std::bitset<8> &cubeBit);

		Point* calculatePoint(std::bitset<8> id, float density1, float density2, vector3 position1, vector3 position2, vector3 normal);

		void constructTriangle(std::vector<Point *> &points, std::bitset<8> triBit[12]);

		Point* findPointByID(std::vector<Point *> &points, std::bitset<8> triBit);

};

#endif